package fun.boomcat.luckyhe.mirai.plugin.botcontrol.util;

import fun.boomcat.luckyhe.mirai.plugin.botcontrol.pojo.Config;
import net.mamoe.mirai.console.command.CommandSender;

import java.io.IOException;

/**
 * @author Lucky_He
 * @date 2021年8月29日 7:41
 * @description OwnerQQOperation
 */
public class OwnerQQOperation {
    public static void ownerQQOperation(CommandSender commandSender, Object[] args) {
//        对主人QQ的操作
        Config config;
        try {
            config = ConfigUtil.getConfig();
        } catch (IOException e) {
            commandSender.sendMessage("错误：" + e.toString());
            return;
        }

        String newOwnerQQ = args[0].toString();
        long nqq;
        try {
            nqq = Long.parseLong(newOwnerQQ);
        } catch (Exception e) {
            commandSender.sendMessage("错误：" + e.toString());
            return;
        }

        config.setOwnerQQ(nqq);
        try {
            ConfigUtil.writeConfig();
        } catch (IOException e) {
            commandSender.sendMessage("错误：" + e.toString());
        }

        commandSender.sendMessage("已将owner的QQ设置为：" + config.getOwnerQQ());
    }
}
